#include "SoundSample.h"
#include <cmath>

using namespace std;

SoundSample::SoundSample(QString filepath)
{
    // set the filepath
    this->mFilepath = filepath;
}

SoundSample::~SoundSample()
{
}

void SoundSample::setFilesize(long fs) 
{ 
	// fs is in bytes
	double tempSize;
	char filesizeString[10];
	
	if (fs > pow(1000.0, 3) ) // gb
	{
		tempSize = fs / pow(1000.0 ,3);
		
		// get only the first two decimal places
		sprintf( filesizeString, "%.2lf GB", tempSize);
		this->mFilesize = QString(filesizeString);
	}
	else if (fs > pow(1000.0, 2)) // MB
	{
		tempSize = fs / pow(1000.0 ,2);
		
		// get only the first two decimal places
		sprintf( filesizeString, "%.2lf MB", tempSize);
		this->mFilesize = QString(filesizeString);
				  
	} 
	else if ( fs > ( 1000 )) // KB
	{
		int intSize = ceil( fs / 1000.0 );
		
		// get only the first two decimal places
		sprintf( filesizeString, "%i KB", intSize);
		this->mFilesize = QString(filesizeString);
	}
}

// pass the length in seconds
void SoundSample::setLength(int length)
{ 
	int minutes = length / 60;
	int seconds = length - (minutes*60);
	
	char time[10];
	
	if (seconds < 10) {
		sprintf(time, "%2i : 0%i", minutes, seconds);
	}
	else 
	{
		sprintf(time, "%2i : %i", minutes, seconds);
	}
	
	this->mLength = QString(time); 
}



